<?php
//
namespace app\circle\controller\admin;

use think\Controller;
use think\Request;

class BaseController extends \think\Controller
{

    public $adminInfo;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $circleDes = cookie('circleDes');
        $loginUrl = url('admin.public/login');
        if(empty($circleDes)){
            $this->error('请先登录1！',$loginUrl);
        }
        $info = str_decode($circleDes);
        if(empty($info)){
            $this->error('请先登录2！',$loginUrl);
        }else{
            $info = explode(config('base.login_token'), $info);
            if(count($info)==8){
                $this->adminInfo = $this->formatAdmin($info);
                $this->assign('adminInfo',$this->adminInfo);
            }else{
                $this->error('请先登录3！',$loginUrl);
            }
        }
    }

    private function formatAdmin($info){
        $data['admin_id'] = $info[0];
        $data['admin_name'] = $info[1];
        $data['admin_truename'] = $info[2];
        $data['dept_id'] = $info[3];
        $data['dept_name'] = $info[4];
        $data['dept_path'] = $info[5];
        $data['dept_level'] = $info[6];
        $data['admin_power'] = $info[7];
        return $data;
    }

}
